package algotithm.jianzhioffer.test54;


class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    public TreeNode (int val) {
        this.val = val;
    }
}
/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/15-23:19
 */
public class Solution {

    int res,k;
    public int kthLargest(TreeNode root, int k) {
        this.k = k;
        dfs(root);
        return res;
    }

    public void dfs(TreeNode root) {
        if (root == null) {
            return;
        }
        if (k == 0) {
            return;
        }
        dfs(root.right);
        if (--k == 0) {
            res = root.val;
        }
        dfs(root.left);
    }
}
